package com.bosssoft.setp.model.business.course;

import com.bosssoft.setp.handler.CourseTypeDataProxy;
import xyz.erupt.annotation.Erupt;
import xyz.erupt.annotation.EruptField;
import xyz.erupt.annotation.PreDataProxy;
import xyz.erupt.annotation.sub_erupt.Tree;
import xyz.erupt.annotation.sub_field.Edit;
import xyz.erupt.annotation.sub_field.EditType;
import xyz.erupt.annotation.sub_field.Readonly;
import xyz.erupt.annotation.sub_field.View;
import xyz.erupt.annotation.sub_field.sub_edit.ReferenceTreeType;
import xyz.erupt.jpa.model.BaseModel;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

/**
 * 课程类别实体的类定义
 *
 * @author clt
 */
@Entity
@Table(name = "setp_course_type")
@Erupt(
        name = "课程类别管理",
        tree = @Tree(pid = "parent.id")
)
@PreDataProxy(CourseTypeDataProxy.class)
public class CourseType extends BaseModel {
    @EruptField(
            views = @View(title = "课程类别名"),
            edit = @Edit(title = "课程类别名", notNull = true)
    )
    private String name;

    @ManyToOne
    @EruptField(
            edit = @Edit(
                    title = "上一级类别",
                    type = EditType.REFERENCE_TREE,
                    referenceTreeType = @ReferenceTreeType(pid = "parent.id")
            )
    )
    private CourseType parent;

    @EruptField(
            views = @View(title = "备注"),
            edit = @Edit(title = "备注")
    )
    private String remark;

    @EruptField(
            views = @View(title = "编码"),
            edit = @Edit(title = "编码", readonly = @Readonly(edit = false), placeHolder = "新增不需要输入")
    )
    private String code;

    private Integer level;

    public Integer getLevel() {
        return level;
    }

    public String getName() {
        return name;
    }

    public Long getParentId() {
        if(parent == null){
            return null;
        }

        return parent.getId();
    }
    public String getParentName() {
        if(parent == null){
            return null;
        }

        return parent.getName();
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getParentLevel() {
        if(parent != null){
            return parent.level;
        }else {
            return null;
        }
    }

    public void setLevel(int i) {
        this.level = i;
    }

    public void setCode(String format) {
        this.code = format;
    }

    public String getCode() {
        return code;
    }
}